﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace VietKinsNutrition.Data
{
    public class ClsTblGiaDAL
    {
        ClsBindingBLL ClsBin = new ClsBindingBLL();

        public DataTable SelectAll()
        {
            string NamePrc = QueryString.SPROC_TBLGIA_GET;
            string NameTable = "TblGia";
            DataSet Dset = new DataSet();
            DataTable NewTable = new DataTable();
            NewTable.TableName = NameTable;

            DataColumn Columm = new DataColumn();
            Columm.ColumnName = Columm.Caption = "STT";
            Columm.DataType = System.Type.GetType("System.Int32");
            Columm.AllowDBNull = false;
            Columm.AutoIncrement = true;
            Columm.AutoIncrementSeed = Columm.AutoIncrementStep = 1;
            NewTable.Columns.Add(Columm);
            Dset.Tables.Add(NewTable);
            OleDbCommand Cmm = new OleDbCommand();
            OleDbDataAdapter Dap;
            Cmm.Connection = ClsConnection.OleDBConnect();
            Cmm.CommandText = NamePrc;
            try
            {
                if (Cmm.Connection.State != ConnectionState.Open) Cmm.Connection.Open(); Cmm.ExecuteNonQuery();
            }
            catch (Exception Ex)
            {
            }
            finally
            {
                Cmm.Connection.Close();
            }
            Dap = new OleDbDataAdapter(Cmm);

            Dap.Fill(Dset.Tables[NameTable]);
            return Dset.Tables[NameTable];
        }
        public void Insert(float Nhombot, float Nhomchao, float Nhatre, float Maugiao)
        {
            string NamePrc = "INSERT INTO TblGia(nhombot,nhomchao, nhatre,maugiao) VALUES (" + Nhombot.ToString() + "," + Nhomchao.ToString() + "," + Nhatre.ToString() + "," + Maugiao.ToString() + ")";
            OleDbCommand Cmm = new OleDbCommand();
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
        }

        public void Edit(int Id, float Nhombot, float Nhomchao, float Nhatre, float Maugiao)
        {
            string NamePrc = "UPDATE TblGia SET nhombot = " + Nhombot.ToString() + ", nhomchao =" + Nhomchao.ToString() + ", nhatre=" + Nhatre.ToString() + ",maugiao=" + Maugiao.ToString() + " WHERE Id = " + Id.ToString() + "";
            OleDbCommand Cmm = new OleDbCommand();
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
        }

    }
}
